package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
)

type SignUserInfo struct {
	Name       string   `form:"name" json:"name" binding:""`
	NickName   string   `form:"nickName" json:"nickName" binding:"contains=m"`
	Age        int      `form:"age" json:"age" binding:"lt=30,gt=18"`
	Password   string   `form:"password" json:"password" binding:""`
	RePassword string   `form:"rePassword" json:"rePassword" binding:"eqfield=Password"`
	Sex        string   `form:"sex" json:"sex" binding:"oneof=man woman"`
	LikeList   []string `form:"likeList" json:"likeList" binding:"required,dive,startswith=i"`
	IP         string   `form:"ip" json:"ip" binding:"ip"`
	URL        string   `form:"url" json:"url" binding:"url"`
	Date       string   `form:"date" json:"date" binding:"datetime=2006-01-01 00:00:00"`
}

func main() {
	router := gin.Default()

	router.POST("/", func(c *gin.Context) {
		var user SignUserInfo
		err := c.ShouldBindJSON(&user)
		if err != nil {
			fmt.Println(err)
			c.JSON(http.StatusOK, gin.H{"msg": err.Error()})
			return
		}
		c.JSON(http.StatusOK, gin.H{"msg": user})
	})
	router.Run(":8080")
}
